import GUI from 'lil-gui'

const gui = new GUI({
  title: '测试列表',
})
let folder:GUI
export function getGUI (title: string) {
  folder?.destroy()
  folder = gui.addFolder(title)
  return folder
}

const tests = import.meta.glob('../tests/*.ts')

const menu: any = {}

for (const key in tests) {
  const exec = /\/([\u4e00-\u9fa5]+)\.ts/.exec(key)
  if (exec) {
    const name = exec[1]
    menu[name] = () => {
      location.href = './#/' + name
    }
    gui.add(menu, name)
  }
}

async function locate () {
  const hash = decodeURI(location.hash)
  const key = hash.replace('#', '../tests') + '.ts'
  const demo = tests[key]
  if (demo) {
    const res: any = await demo()
    res.main()
  }
}
window.onhashchange = locate

locate()


